package binarysearch.test35;

/**
 * 搜索插入位置
 *
 * @author code_yc
 * @version 1.0
 * @date 2020/7/11 10:03
 */
public class Solution1 {

    public int searchInsert(int[] nums, int target) {
        if (nums == null || nums.length == 0) return 0;
        int l = 0, r = nums.length;
        while (l < r) {
            int mid = l + ((r - l) >> 1);
            if (nums[mid] == target) {
                return mid;
            } else if (nums[mid] < target) {
                l = mid + 1;
            } else {
                r = mid;
            }
        }
        return l;
    }
}
